package com.dream.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dream.commons.base.BaseController;
import com.dream.commons.shiro.ShiroUser;
import com.dream.commons.utils.JsonUtils;
import com.dream.model.DTO.MenuDto;
import com.dream.model.DTO.resourceDto.ResourceTreeDto;
import com.dream.service.ResourceService;

/**
 * @description：资源管理
 */
@Controller
@RequestMapping("/resource")
public class ResourceController extends BaseController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 左菜单树
     * @return
     */
    @PostMapping("/leftMenu")
    @ResponseBody
    public Object tree() {
        ShiroUser shiroUser = getShiroUser();
        List<MenuDto> fatherMenu =  resourceService.getLeftMenu(shiroUser);
        return fatherMenu;
    }
    
    @GetMapping("/manager")
    public Object resourceList(Model model) {
    	List<ResourceTreeDto> resourceTreeDtos =  resourceService.selectLayuiTreeTable();
    	String jsonString = JsonUtils.toJson(resourceTreeDtos);
    	model.addAttribute("resTreeTable",jsonString);
        return "admin/resourceList";
    }
    
}
